package com.it.controller;

import com.it.pojo.Dept;
import com.it.service.DeptFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 消费者无需使用Service层，直接调用远程
 * <p>
 * RestTemplate模板类，通过 配置类 注册到Spring，直接调用内部方法
 */
@RestController
@RequestMapping("/consumer")
public class DeptConsumerController {

    @Autowired
    private DeptFeignService service;

    @RequestMapping("/add")
    public boolean addDept(@RequestBody Dept dept) {
        return service.addDept(dept);
    }

    @RequestMapping("/get/{id}")
    public Dept getDept(@PathVariable("id") Long id) {
        return service.queryById(id);
    }

    @RequestMapping("/getAll")
    public List<Dept> getAllDept() {
        return service.queryAll();
    }

}
